/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.api.adwords.starterkit.examples.enhancedads;

import com.google.api.adwords.starterkit.utils.SettingsException;

/**
 * The enum CollectionRule specifies the types of operations used by
 * collection items rules.
 * 
 * @author rodrigo.f.vale@gmail.com
 *  
 */
public enum CollectionRule {
  CONTAINS, EQUALS, GREATER_THAN, LOWER_THAN, GREATER_EQUAL_THAN, 
  LOWER_EQUAL_THAN;
  
  public static CollectionRule fromString(String rule) 
      throws SettingsException {
    CollectionRule collectionRule = null;
    if (rule.toUpperCase().equals("EQUALS")) {
      collectionRule = CollectionRule.EQUALS;
    } else if (rule.toUpperCase().equals("CONTAINS")) {
      collectionRule = CollectionRule.CONTAINS;
    } else if (rule.toUpperCase().equals("GREATER_EQUAL_THAN")) {
      collectionRule = CollectionRule.GREATER_EQUAL_THAN;
    } else if (rule.toUpperCase().equals("GREATER_THAN")) {
      collectionRule = CollectionRule.GREATER_THAN;
    } else if (rule.toUpperCase().equals("LOWER_EQUAL_THAN")) {
      collectionRule = CollectionRule.LOWER_EQUAL_THAN;
    } else if (rule.toUpperCase().equals("LOWER_THAN")) {
      collectionRule = CollectionRule.LOWER_THAN;
    } else if (rule.toUpperCase().equals("IN")) {
      collectionRule = CollectionRule.CONTAINS;
    }    
    
    if (collectionRule == null) {
      throw new SettingsException("Invalid rule for Collections. Value found: "
          + rule);
    }
    
    return collectionRule;
  }
}